import pymysql

conn = pymysql.connect(
    host='47.93.226.160',
    port=3306,
    db='python_test',
    user='root',
    password='123456'
)
# 获取游标,之后所有的操作通过游标执行
# cursor = conn.cursor()
cursor = conn.cursor(pymysql.cursors.DictCursor)  # 基于字典获取数据

#############################################
# 增 删 改
add_sql = 'insert into user(name,age) values(%s, %s)'
# cursor.execute(add_sql, ('威斯布鲁克', 29))

# 批量执行
# cursor.executemany(add_sql, [('威斯布鲁克', 29), ('科比', 33), ('杜兰特', 32)])

sql = 'select * from user'

cursor.execute(sql)
lst = cursor.fetchall()
print(lst)

cursor.close()
conn.close()
